package fr.umlv.m2.jee.portailEtudiant.web;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: soufiane
 * Date: 19/04/11
 * Time: 20:31
 * To change this template use File | Settings | File Templates.
 */
public class AllowAccessInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 1L;


	public void init(){
		System.out.println("dans la méthode init.......");
	}

	public String intercept(ActionInvocation arg0) throws Exception {


		System.out.println("dans la méthode intercept.......");

		Map<String, Object> session = arg0.getInvocationContext().getSession();

		if(session.get("allowAccess")==null)
		{
			return "input";
		}else
			{
				if (!session.isEmpty())
				{
					return arg0.invoke();
				}
				else
				{
					return "allowAccess";
				}
			}
	}
}
